<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 创建对象发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <button>点击获取段子</button>
    <button>本地server</button>

    <script>
        //创建 axios 对象,  是为了简化代码
        //针对 api.xiaohigh.com:8090
        let axios1 = axios.create({
            baseURL: 'http://api.xiaohigh.com:8090',
            method: 'get',
        });

        //针对 localhost:8023
        let axios2 = axios.create({
            baseURL: 'http://localhost:8023'
        })
        
        //获取按钮
        let btns = document.querySelectorAll('button');
        
        //绑定事件
        btns[0].onclick = async function(){
            let result = await axios1({
                url: '/duanzi'
            });
            console.log(result);
        }

        btns[1].onclick = async function(){
            let result = await axios2('/server');
            console.log(result);
        }

    </script>
</body>
</html>